package com.slf.flow.core.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import com.slf.flow.core.model.TrendsData;

import java.util.List;
import java.util.Map;

@Mapper
public interface TrendsDataMapper extends BaseMapper<TrendsData>{

    @Select("SELECT t1.day, IFNULL(tos.count, 0) as count FROM (\n" +
            "    SELECT @cdate := DATE_ADD(@cdate, INTERVAL - 1 DAY) day \n" +
            "    FROM (SELECT @cdate := DATE_ADD(DATE_FORMAT(SYSDATE(),'%Y-%m-%d'), INTERVAL + 1 DAY) FROM sp_trends_data) t0\n" +
            "    LIMIT 7\n" +
            ") t1 \n" +
            "LEFT JOIN (\n" +
            "    select DATE_FORMAT(update_time,'%Y-%m-%d') day, count(*) count from (\n" +
            "        select * from sp_trends_data where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(update_time)\n" +
            "    ) as take_order_statistics group by day\n" +
            ") tos\n" +
            "ON t1.day = tos.day")
    List<Map<String, String>> week(Map<String, String> map);
}
